<template>
  <div class="qxgl_page">
    <headercom></headercom>
    <div class="bcg left_bcg">
      <div class="qx_hedlist hedlist">
        <div class="headbtn">
          <a-button type="primary" @click="addnewkh">新增用户</a-button>
        </div>
        <div class="head_search">
          <div class="sele">
            <a-input
              placeholder="请输入姓名或编码"
              v-model="keywords"
              style="width: 200px"
              @change="searchqxlist"
            />
            <a-icon type="search" class="search" />
          </div>
        </div>
      </div>
      <div class="add_newkh" v-if="addhk_flag">
        <div class="kh_from">
          <div class="close" @click="close">
            <a-icon type="close" />
          </div>
          <p class="tit">新增用户</p>
          <ul>
            <li>
              <span class="inp_tit">
                <span class="red">*</span>公司编码
              </span>
              <a-select
                v-model="gsbm_sel"
                style="width: 300px"
                :value="gsbm_sel"
                placeholder="请选择公司编码"
                @change="gsbmChange"
              >
                <a-select-option v-for="(item, i) in qxlist" :key="i" :value="item.gsbm">{{item.gsbm}}</a-select-option>
              </a-select>
            </li>
            <li>
              <span class="inp_tit">
                <span class="red">*</span>用户姓名
              </span>
              <a-input
                type="text"
                v-model="username"
                name
                placeholder="请输入用户姓名"
                style="width: 300px"
                id
              />
            </li>
            <li>
              <span class="inp_tit">
                <span class="red">*</span>用户编码
              </span>
              <a-input
                type="text"
                v-model="yhbm"
                name
                placeholder="请输入用户编码"
                style="width: 300px"
                id
              />
            </li>
            <li>
              <span class="inp_tit">手机号码</span>
              <a-input
                type="text"
                v-model="phone"
                name
                placeholder="请输入手机号码"
                style="width: 300px"
                id
              />
            </li>
            <li>
              <span class="inp_tit">登录密码</span>
              <a-input
                type="text"
                v-model="password"
                name
                placeholder="请输入登录密码"
                style="width: 300px"
                id
              />
            </li>
            <li>
              <p class="red">注：请勿删除开通手机查询端绑定的手机号码！</p>
            </li>
            <li class="btn_li">
              <a-button @click="close">取消</a-button>
              <a-button type="primary" @click="savkh">保存</a-button>
            </li>
          </ul>
        </div>
      </div>
      <div class="qxgl_box">
        <div class="qxlb">
          <ul>
            <li v-for="(item, i) in qxlist" :key="i">
              <p class="gsmc_tit" @click="qxtab(i+1)">
                <a-icon type="minus-square" class="add_ico" v-if="qx_table==i+1?true:false" />
                <a-icon type="plus-square" class="add_ico" v-if="qx_table==i+1?false:true" />
                {{item.gsbm}} {{item.gsmc}}
              </p>
              <div class="qx_gl_ry" v-if="qx_table==i+1?true:false">
                <!-- <div class="spin_box" v-if="spin_flag">
                  <a-spin size="large" />
                </div>-->
                <div v-if="spin_flag" class="spin_box">
                  <a-spin tip="加载中....." size="large"></a-spin>
                </div>
                <a-table :columns="columns" :data-source="item.user" :pagination="false">
                  <template slot="operation" slot-scope="text, record">
                    <!-- <a href="javascript:;"  class="del">密码重置</a> -->
                    <a-popconfirm title="确定密码重置吗?" @confirm="() => onpassword(record.key,record)">
                      <a href="javascript:;" class="del">密码重置</a>
                    </a-popconfirm>
                    <a-popconfirm title="确定删除吗?" @confirm="() => onDelete(record.key,record)">
                      <a href="javascript:;" class="del">删除</a>
                    </a-popconfirm>
                    <a href="javascript:;" class="del" @click="qxlistclick(record)">权限</a>
                  </template>
                </a-table>
              </div>
            </li>
            <!-- <li>
              <p class="gsmc_tit" @click="qxtab(2)">
                <a-icon type="minus-circle" class="add_ico" v-if="qx_table==2?true:false" />
                <a-icon type="plus-circle" class="add_ico" v-if="qx_table==2?false:true" />BBL 西安佰联网络技术有限公司
              </p>
              <div class="qx_gl_ry" v-if="qx_table==2?true:false">
                <a-table :columns="columns" :data-source="data" :pagination="false">
                  <template slot="operation" slot-scope="text, record">
                    <a href class="del">密码重置</a>
                    <a href class="del">删除</a>
                    <a href class="del">权限</a>
                  </template>
                </a-table>
              </div>
            </li>-->
          </ul>
        </div>
      </div>

      <div class="qxgl_tk" v-if="qxgl_tk_flag">
        <div class="qx_edit">
          <div class="edit_spin_box" v-if="qxloding_flag">
            <a-spin tip="加载中....." size="large"></a-spin>
          </div>
          <a-tabs default-active-key="gn" @change="callback">
            <a-tab-pane key="gn" tab="功能权限">
              <div class="tab_box">
                <!-- <span @click="allchecked">全选</span> -->
                <div class="check_box">
                  <a-checkbox @click="allchecked" :checked="allcheckbox">全选</a-checkbox>
                  <span class="can_check" @click="cancheck">取消</span>
                </div>
                <a-tree
                  checkable
                  :tree-data="treeData"
                  v-model="checkedKeys"
                  :expanded-keys="expandedKeys"
                  :auto-expand-parent="autoExpandParent"
                  :selected-keys="selectedKeys"
                  @select="onSelect"
                  @check="onCheck"
                  @expand="onExpand"
                ></a-tree>
              </div>
            </a-tab-pane>
            <a-tab-pane key="jg" tab="价格权限">
              <div class="tab_box">
                <div class="check_box">
                  <a-checkbox @click="allchecked" :checked="allcheckbox">全选</a-checkbox>
                  <span class="can_check" @click="cancheck">取消</span>
                </div>
                <a-tree
                  checkable
                  :tree-data="treeData"
                  v-model="checkedKeys"
                  :expanded-keys="expandedKeys"
                  :auto-expand-parent="autoExpandParent"
                  :selected-keys="selectedKeys"
                  @select="onSelect"
                  @check="onCheck"
                  @expand="onExpand"
                ></a-tree>
              </div>
            </a-tab-pane>
            <a-tab-pane key="xs" tab="下属设定">
              <div class="tab_box">
                <div class="check_box">
                  <a-checkbox @click="allchecked" :checked="allcheckbox">全选</a-checkbox>
                  <span class="can_check" @click="cancheck">取消</span>
                </div>
                <a-tree
                  checkable
                  :tree-data="treeData"
                  v-model="checkedKeys"
                  :expanded-keys="expandedKeys"
                  :auto-expand-parent="autoExpandParent"
                  :selected-keys="selectedKeys"
                  @select="onSelect"
                  @check="onCheck"
                  @expand="onExpand"
                ></a-tree>
              </div>
            </a-tab-pane>
            <div class="close" @click="close">
              <a-icon type="close-circle" />
            </div>
          </a-tabs>
          <div class="qx_btn_box">
            <a-button @click="close">取消</a-button>
            <a-button type="primary" @click="savchecked">保存</a-button>
          </div>
        </div>
      </div>
    </div>
    <rightnav></rightnav>
  </div>
</template>

<script>
import headercom from "../../header-comm/header.vue";
import rightnav from "../rightnav.vue";
import qs from "qs";
const columns = [
  {
    title: "姓名",
    dataIndex: "NAME",
    key: "NAME"
  },
  {
    title: "归属",
    dataIndex: "GSBM",
    key: "GSBM"
  },
  {
    title: "编码",
    dataIndex: "YHDM",
    key: "YHDM"
  },
  {
    title: "手机",
    dataIndex: "sjhm",
    key: "sjhm"
  },
  {
    title: "类型",
    dataIndex: "yhfl",
    key: "yhfl"
  },
  {
    title: "销售限价",
    dataIndex: "xtbj",
    key: "xtbj",
    ellipsis: true
  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" }
  }
];

const data = [
  {
    key: "1",
    name: "业务员",
    guishu: "归属",
    gsbm: "BBL",
    phone: "17691396256",
    lx: "1",
    xsxj: "2"
  }
];
const treeData = [
  {
    // title: "parent 1",
    // key: "0",
    // children: [
    //   {
    //     title: "parent 1-0",
    //     key: "0-0",
    //     children: [
    //       { title: "leaf", key: "0-0-0" },
    //       { title: "leaf", key: "0-0-1" }
    //     ]
    //   },
    //   {
    //     title: "parent 1-1",
    //     key: "0-0-1",
    //     children: [{ key: "0-0-1-0", slots: { title: "title0010" } }]
    //   }
    // ]
  }
];
export default {
  data() {
    return {
      data,
      columns,
      qx_table: 1,
      treeData: "",

      expandedKeys: [],
      autoExpandParent: true,
      checkedKeys: [],
      selectedKeys: [],

      qxgl_tk_flag: false,
      qxlist: "",
      keywords: "",
      tab_current: "gn",
      qxvalue: "",
      spin_flag: false,
      qxloding_flag: false,
      addhk_flag: false,

      gsbm_sel: undefined,
      username: "",
      yhbm: "",
      phone: "",
      password: "",
      allcheckbox: false
    };
  },

  methods: {
    qxtab(key) {
      if (this.qx_table == key) {
        this.qx_table = 0;
      } else {
        this.qx_table = key;
      }
    },
    onDelete(key, value) {
      console.log(value);
      this.axios
        .post(
          this.$store.state.baseurl + "/wxapi/samt_UserDel.php",
          qs.stringify({
            token: sessionStorage.getItem("smt_token"),
            id_num: value.ID_NUM,
            gsbm: value.GSBM,
            name: value.NAME
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
            this.getqxgl(this.keywords);
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    onpassword(key, value) {
      console.log(value);
      this.axios
        .post(
          this.$store.state.baseurl + "/wxapi/samt_passwordSet.php",
          qs.stringify({
            token: sessionStorage.getItem("smt_token"),
            id_num: value.ID_NUM
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },

    callback(key) {
      console.log(key);
      this.tab_current = key;
      this.treeData = [];
      this.checkedKeys = [];

      this.qxlistclick(this.qxvalue);
    },
    onExpand(expandedKeys) {
      console.log("onExpand", expandedKeys);
      this.expandedKeys = expandedKeys;
      this.autoExpandParent = false;
    },
    onSelect(selectedKeys, info) {
      console.log("selected", selectedKeys, info);
    },
    onCheck(checkedKeys, info) {
      // console.log("onCheck", checkedKeys);
      console.log("info", info);
      var parent_node_key = info.node.eventKey; //最外层key
      var child_node_key = ""; //第二层key
      var node_key = ""; //第三层当前key
      var key_node = parent_node_key.split("-");
      console.log(key_node);

      if (key_node.length == 2) {
        parent_node_key = key_node[0] + "-" + key_node[1];
      }
      if (key_node.length == 3) {
        parent_node_key = key_node[0] + "-" + key_node[1];
        child_node_key = key_node[0] + "-" + key_node[1] + "-" + key_node[2]; //第二层key
      }
      if (key_node.length == 4) {
        parent_node_key = key_node[0] + "-" + key_node[1];
        child_node_key = key_node[0] + "-" + key_node[1] + "-" + key_node[2]; //第二层key
        node_key =
          key_node[0] +
          "-" +
          key_node[1] +
          "-" +
          key_node[2] +
          "-" +
          key_node[3]; //第三层key
      }

      console.log(parent_node_key);
      console.log(child_node_key);
      console.log(node_key);
      if (info.checked) {
        for (var i = 0; i < this.treeData.length; i++) {
          if (key_node.length == 2) {
            //第一层树
            if (this.treeData[i].key == parent_node_key) {
              console.log(this.treeData[i]);
              this.treeData[i].checked = true;
              this.treeData[i].checked_c = true;
              if (this.treeData[i].children) {
                for (var j = 0; j < this.treeData[i].children.length; j++) {
                  this.treeData[i].children[j].checked = true;
                  this.treeData[i].children[j].checked_c = true;
                  if (this.treeData[i].children[j].children) {
                    for (
                      var k = 0;
                      k < this.treeData[i].children[j].children.length;
                      k++
                    ) {
                      this.treeData[i].children[j].children[k].checked = true;
                      this.treeData[i].children[j].children[k].checked_c = true;
                    }
                  }
                }
              }
            }
          }
          if (key_node.length == 3) {
            //第二层树
            if (this.treeData[i].key == parent_node_key) {
              // console.log(this.treeData[i]);
              this.treeData[i].checked_c = true;
              if (this.treeData[i].children) {
                for (var j = 0; j < this.treeData[i].children.length; j++) {
                  if (this.treeData[i].children[j].key == child_node_key) {
                    console.log(this.treeData[i]);

                    this.treeData[i].children[j].checked = true;
                    this.treeData[i].children[j].checked_c = true;
                    if (this.treeData[i].children[j].children) {
                      for (
                        var k = 0;
                        k < this.treeData[i].children[j].children.length;
                        k++
                      ) {
                        this.treeData[i].children[j].children[k].checked = true;
                        this.treeData[i].children[j].children[
                          k
                        ].checked_c = true;
                      }
                    }
                  }
                }
              }
            }
          }
          if (key_node.length == 4) {
            //第三层树
            if (this.treeData[i].key == parent_node_key) {
              // console.log(this.treeData[i]);
              this.treeData[i].checked_c = true;
              if (this.treeData[i].children) {
                for (var j = 0; j < this.treeData[i].children.length; j++) {
                  if (this.treeData[i].children[j].key == child_node_key) {
                    console.log(this.treeData[i]);

                    // this.treeData[i].children[j].checked = true;
                    this.treeData[i].children[j].checked_c = true;
                    if (this.treeData[i].children[j].children) {
                      for (
                        var k = 0;
                        k < this.treeData[i].children[j].children.length;
                        k++
                      ) {
                        if (
                          this.treeData[i].children[j].children[k].key ==
                          node_key
                        ) {
                          this.treeData[i].children[j].children[
                            k
                          ].checked = true;
                          this.treeData[i].children[j].children[
                            k
                          ].checked_c = true;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      } else {
        for (var i = 0; i < this.treeData.length; i++) {
          if (key_node.length == 2) {
            if (this.treeData[i].key == parent_node_key) {
              console.log(this.treeData[i]);
              this.treeData[i].checked = false;
              this.treeData[i].checked_c = false;
              if (this.treeData[i].children) {
                for (var j = 0; j < this.treeData[i].children.length; j++) {
                  this.treeData[i].children[j].checked = false;
                  this.treeData[i].children[j].checked_c = false;
                  if (this.treeData[i].children[j].children) {
                    for (
                      var k = 0;
                      k < this.treeData[i].children[j].children.length;
                      k++
                    ) {
                      this.treeData[i].children[j].children[k].checked = false;
                      this.treeData[i].children[j].children[
                        k
                      ].checked_c = false;
                    }
                  }
                }
              }
            }
          }
          if (key_node.length == 3) {
            //第二层树
            if (this.treeData[i].key == parent_node_key) {
              // console.log(this.treeData[i]);

              this.treeData[i].checked_c = false;
              if (this.treeData[i].children) {
                for (var j = 0; j < this.treeData[i].children.length; j++) {
                  if (this.treeData[i].children[j].key == child_node_key) {
                    console.log(this.treeData[i]);

                    this.treeData[i].children[j].checked = false;
                    this.treeData[i].children[j].checked_c = false;
                    if (this.treeData[i].children[j].children) {
                      for (
                        var k = 0;
                        k < this.treeData[i].children[j].children.length;
                        k++
                      ) {
                        this.treeData[i].children[j].children[
                          k
                        ].checked = false;
                        this.treeData[i].children[j].children[
                          k
                        ].checked_c = false;
                      }
                    }
                  }
                }
              }
            }
          }
          if (key_node.length == 4) {
            //第三层树
            if (this.treeData[i].key == parent_node_key) {
              // console.log(this.treeData[i]);
              this.treeData[i].checked = true;
              this.treeData[i].checked_c = false;
              if (this.treeData[i].children) {
                for (var j = 0; j < this.treeData[i].children.length; j++) {
                  if (this.treeData[i].children[j].key == child_node_key) {
                    console.log(this.treeData[i]);
                    this.treeData[i].children[j].checked = true;
                    this.treeData[i].children[j].checked_c = false;
                    if (this.treeData[i].children[j].children) {
                      for (
                        var k = 0;
                        k < this.treeData[i].children[j].children.length;
                        k++
                      ) {
                        if (
                          this.treeData[i].children[j].children[k].key ==
                          node_key
                        ) {
                          this.treeData[i].children[j].children[
                            k
                          ].checked = false;
                          this.treeData[i].children[j].children[
                            k
                          ].checked_c = false;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }

      // for (var i = 0; i < this.treeData.length; i++) {
      //   // this.treeData[i].
      //   if (info.checked) {
      //     if (this.treeData[i].key == parent_node_key) {
      //       console.log(this.treeData[i]);

      //       console.log("11111111trueeeeeeeeeeee");
      //       console.log("this.treeData[i].key", this.treeData[i].key);
      //       if (key_node.length == 2) {
      //         this.treeData[i].checked = true;
      //         this.treeData[i].checked_c = true;
      //       }
      //       if (this.treeData[i].children) {
      //         //第二层开始

      //         for (var j = 0; j < this.treeData[i].children.length; j++) {
      //           if (this.treeData[i].checked && this.treeData[i].checked_c) {
      //             this.treeData[i].children[j].checked = true;
      //             this.treeData[i].children[j].checked_c = true;
      //           }
      //           if (key_node.length == 3) {
      //             if (this.treeData[i].children[j].key == child_node_key) {
      //               console.log("1-------------trueeeeeeeeeeee");

      //               // console.log(this.treeData[i]);
      //               this.treeData[i].children[j].checked = true;
      //               this.treeData[i].children[j].checked_c = true;
      //               this.treeData[i].checked_c = true;
      //               // }
      //               if (this.treeData[i].children[j].children) {
      //                 //第三层开始
      //                 for (
      //                   let k = 0;
      //                   k < this.treeData[i].children[j].children.length;
      //                   k++
      //                 ) {
      //                   if (
      //                     this.treeData[i].checked &&
      //                     this.treeData[i].checked_c
      //                   ) {
      //                     this.treeData[i].children[j].children[
      //                       k
      //                     ].checked = true;
      //                     this.treeData[i].children[j].children[
      //                       k
      //                     ].checked_c = true;
      //                   }
      //                   if (
      //                     this.treeData[i].children[j].checked &&
      //                     this.treeData[i].children[j].checked_c
      //                   ) {
      //                     this.treeData[i].children[j].children[
      //                       k
      //                     ].checked = true;
      //                     this.treeData[i].children[j].children[
      //                       k
      //                     ].checked_c = true;
      //                   }
      //                   if (key_node.length == 3) {
      //                     if (
      //                       this.treeData[i].children[j].children[k].key ==
      //                       node_key
      //                     ) {
      //                       this.treeData[i].children[j].children[
      //                         k
      //                       ].checked = true;
      //                       this.treeData[i].children[j].children[
      //                         k
      //                       ].checked_c = true;
      //                       this.treeData[i].children[j].checked_c = true;
      //                       this.treeData[i].checked_c = true;
      //                     }
      //                   }
      //                 }
      //               }
      //             }
      //           }
      //         }
      //       }
      //       // if (this.treeData[i].checked_c && this.treeData[i].checked) {
      //       //   this.allcheckbox = true;
      //       //   console.log("this.allcheckbox11111111", this.allcheckbox);
      //       // } else {
      //       //   console.log("this.allcheckbox222222", this.allcheckbox);
      //       //   this.allcheckbox = false;
      //       //   break;
      //       // }
      //       console.log(this.treeData[i]);
      //     }
      //   } else {
      //     console.log("fasleeeeeeeeeeee");
      //     console.log(this.treeData[i].key);
      //     console.log(parent_node_key);
      //     if (this.treeData[i].key == parent_node_key) {
      //       console.log(this.treeData[i].key);
      //       console.log(parent_node_key);
      //       console.log(node_key);
      //       // console.log(this.treeData[i]);
      //       if (key_node.length == 2) {
      //         this.treeData[i].checked = false;
      //         this.treeData[i].checked_c = false;
      //       }
      //       this.allcheckbox = false;

      //       if (this.treeData[i].children) {
      //         //第二层开始
      //         console.log("-------------22222222-------");

      //         for (var j = 0; j < this.treeData[i].children.length; j++) {
      //           // if (!this.treeData[i].checked && !this.treeData[i].checked_c) {
      //           //   this.treeData[i].children[j].checked = false;
      //           //   this.treeData[i].children[j].checked_c = false;
      //           // }
      //           if (key_node.length == 3) {
      //             console.log("-------------333333333-------");

      //             if (this.treeData[i].children[j].key == child_node_key) {
      //               console.log(this.treeData[i]);
      //               this.treeData[i].children[j].checked = false;
      //               this.treeData[i].children[j].checked_c = false;
      //               this.treeData[i].checked_c = false;
      //               // }

      //               if (this.treeData[i].children[j].children) {
      //                 //第三层开始
      //                 // console.log("第三层开始");
      //                 for (
      //                   let k = 0;
      //                   k < this.treeData[i].children[j].children.length;
      //                   k++
      //                 ) {
      //                   // if (
      //                   //   !this.treeData[i].checked &&
      //                   //   !this.treeData[i].checked_c
      //                   // ) {
      //                   //   this.treeData[i].children[j].children[
      //                   //     k
      //                   //   ].checked = false;
      //                   //   this.treeData[i].children[j].children[
      //                   //     k
      //                   //   ].checked_c = false;
      //                   // }
      //                   // if (
      //                   //   !this.treeData[i].children[j].checked &&
      //                   //   !this.treeData[i].children[j].checked_c
      //                   // ) {
      //                   //   this.treeData[i].children[j].children[
      //                   //     k
      //                   //   ].checked = false;
      //                   //   this.treeData[i].children[j].children[
      //                   //     k
      //                   //   ].checked_c = false;
      //                   // }
      //                   if (key_node.length == 4) {
      //                     if (
      //                       this.treeData[i].children[j].children[k].key ==
      //                       node_key
      //                     ) {
      //                       this.treeData[i].children[j].children[
      //                         k
      //                       ].checked = false;
      //                       this.treeData[i].children[j].children[
      //                         k
      //                       ].checked_c = false;
      //                       this.treeData[i].children[j].checked_c = false;
      //                       this.treeData[i].checked_c = false;
      //                     }
      //                   }
      //                 }
      //               }
      //             }
      //           }
      //         }
      //       }
      //       // if (this.treeData[i].checked_c && this.treeData[i].checked) {
      //       //   this.allcheckbox = true;
      //       // } else {
      //       //   this.allcheckbox = false;
      //       // }
      //     }
      //     // console.log(this.treeData[i]);
      //   }
      // }
      // this.treeData = this.treeData;
      console.log(this.treeData);
    },
    cancheck() {
      // this.allcheckbox = false;

      console.log(this.$store.state.qx_checkedbox);
      this.qxlistclick(this.qxvalue);
    },
    allchecked(e) {
      console.log(`checked = ${e.target.checked}`);

      var checked = e.target.checked;
      this.checkedKeys = [];
      this.allcheckbox = e.target.checked;
      for (var i = 0; i < this.treeData.length; i++) {
        if (checked) {
          this.treeData[i].checked = true;
          this.treeData[i].checked_c = true;
          this.checkedKeys.push(this.treeData[i].key);
          if (this.treeData[i].children) {
            for (var j = 0; j < this.treeData[i].children.length; j++) {
              this.treeData[i].children[j].checked = true;
              this.treeData[i].children[j].checked_c = true;
              if (this.treeData[i].children[j].children) {
                for (
                  var k = 0;
                  k < this.treeData[i].children[j].children.length;
                  k++
                ) {
                  this.treeData[i].children[j].children[k].checked = true;
                  this.treeData[i].children[j].children[k].checked_c = true;
                }
              }
            }
          }
        } else {
          this.checkedKeys = [];
          this.treeData[i].checked = false;
          this.treeData[i].checked_c = false;
          if (this.treeData[i].children) {
            for (var j = 0; j < this.treeData[i].children.length; j++) {
              this.treeData[i].children[j].checked = false;
              this.treeData[i].children[j].checked_c = false;
              if (this.treeData[i].children[j].children) {
                for (
                  var k = 0;
                  k < this.treeData[i].children[j].children.length;
                  k++
                ) {
                  this.treeData[i].children[j].children[k].checked = false;
                  this.treeData[i].children[j].children[k].checked_c = false;
                }
              }
            }
          }
        }
      }
      // console.log(this.$store.state.qx_checkedbox);
    },
    qxlistclick(value) {
      this.qxvalue = value;
      this.spin_flag = true;
      this.qxloding_flag = true;
      this.checkedKeys = [];

      // this.allcheckbox = false;
      this.axios
        .post(
          this.$store.state.baseurl + "/wxapi/samt_UserQxGn.php",
          qs.stringify({
            // dk: this.$store.state.dk,
            token: sessionStorage.getItem("smt_token"),
            gsbm: this.qxvalue.GSBM,
            name: this.qxvalue.NAME,
            type: this.tab_current
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.spin_flag = false;
            this.qxloding_flag = false;
            // sessionStorage.setItem
            // this.$store.state.qx_checkedbox = res.data.data;
            for (var i = 0; i < res.data.data.length; i++) {
              if (res.data.data[i].checked && res.data.data[i].checked_c) {
                console.log("-----------", true);
                this.allcheckbox = true;
              } else {
                console.log("-----------", false);
                this.allcheckbox = false;
                break;
              }
            }
            // -----------------------------
            for (var i = 0; i < res.data.data.length; i++) {
              res.data.data[i].title = res.data.data[i].name;
              res.data.data[i].key = "0-" + i;
              if (res.data.data[i].children) {
                for (var j = 0; j < res.data.data[i].children.length; j++) {
                  if (res.data.data[i].children[j].children) {
                    for (
                      var k = 0;
                      k < res.data.data[i].children[j].children.length;
                      k++
                    ) {
                      if (
                        res.data.data[i].children[j].children[k].checked &&
                        res.data.data[i].children[j].children[k].checked_c
                      ) {
                      } else {
                        res.data.data[i].checked_c = false;
                        res.data.data[i].children[j].checked_c = false;
                        res.data.data[i] = res.data.data[i];
                      }
                    }
                  }
                }
              }
              // -----------------------------

              if (res.data.data[i].checked && res.data.data[i].checked_c) {
                this.checkedKeys.push(res.data.data[i].key);
              }
              if (res.data.data[i].children) {
                if (res.data.data[i].children.length) {
                  for (var j = 0; j < res.data.data[i].children.length; j++) {
                    res.data.data[i].children[j].title =
                      res.data.data[i].children[j].name;
                    res.data.data[i].children[j].key = "0-" + i + "-" + j;

                    if (
                      res.data.data[i].children[j].checked &&
                      res.data.data[i].children[j].checked_c
                    ) {
                      this.checkedKeys.push(res.data.data[i].children[j].key);
                    }
                    console.log(this.checkedKeys);
                    if (res.data.data[i].children[j].children.length) {
                      for (
                        var k = 0;
                        k < res.data.data[i].children[j].children.length;
                        k++
                      ) {
                        // if(res.data.data[i].children[j].children[k].checked&&res.data.data[i].children[j].children[k].checked_c){
                        res.data.data[i].children[j].children[k].title =
                          res.data.data[i].children[j].children[k].name;
                        res.data.data[i].children[j].children[k].key =
                          "0-" + i + "-" + j + "-" + k;
                        if (
                          res.data.data[i].children[j].children[k].checked &&
                          res.data.data[i].children[j].children[k].checked_c
                        ) {
                          console.log(
                            res.data.data[i].children[j].children[k].key
                          );
                          this.checkedKeys.push(
                            res.data.data[i].children[j].children[k].key
                          );
                        } else {
                          res.data.data[i].checked_c = false;
                          res.data.data[i].children[j].checked_c = false;
                          res.data.data[i] = res.data.data[i];
                        }

                        // }else if(res.data.data[i].children[j].children[k].checked==false&&res.data.data[i].children[j].children[k].checked_c==false){

                        // }
                      }
                    }
                  }
                }
              }
            }
            this.treeData = res.data.data;
            this.qxgl_tk_flag = true;

            console.log(this.treeData);
            // this.tab_current = 'gn';
          } else {
            this.spin_flag = false;
            this.qxloding_flag = false;
          }
        });
    },
    addnewkh() {
      this.addhk_flag = true;
    },
    // cankh() {
    //   this.addhk_flag = false;
    //   this.gsbm_sel = undefined;
    //   this.username = "";
    //   this.yhbm = "";
    //   this.phone = "";
    //   this.password = "";
    // },
    savkh() {
      console.log(this.gsbm_sel);
      console.log(this.username);
      console.log(this.yhbm);
      console.log(this.phone);
      console.log(this.password);
      if (this.gsbm_sel == "" || this.gsbm_sel == undefined) {
        alert("公司编码不能为空");
        return false;
      }
      if (this.username == "") {
        alert("用户姓名不能为空");
        return false;
      }
      if (this.yhbm == "") {
        alert("用户编码不能为空");
        return false;
      }
      this.axios
        .post(
          this.$store.state.baseurl + "/wxapi/samt_UserAdd.php",
          qs.stringify({
            token: sessionStorage.getItem("smt_token"),

            gsbm: this.gsbm_sel,
            name: this.username,
            yhdm: this.yhbm,
            sjhm: this.phone,
            kl: this.password
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.gsbm_sel = undefined;
            this.username = "";
            this.yhbm = "";
            this.phone = "";
            this.password = "";

            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
            this.addhk_flag = false;
            this.getqxgl();
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    close() {
      this.qxgl_tk_flag = false;
      this.addhk_flag = false;
      this.gsbm_sel = undefined;
      this.tab_current = "gn";
      this.username = "";
      this.yhbm = "";
      this.phone = "";
      this.password = "";

      this.treeData = [];
    },
    searchqxlist() {
      console.log(this.keywords);
      this.getqxgl(this.keywords);
    },
    getqxgl(keywords) {
      this.axios
        .post(
          this.$store.state.baseurl + "/wxapi/samt_qxgl.php",
          qs.stringify({
            token: sessionStorage.getItem("smt_token"),
            keywords: keywords
            // keywords: "王圣磊"
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            for (var i = 0; i < res.data.data.length; i++) {
              res.data.data[i].key = i;
              for (var j = 0; j < res.data.data[i].user.length; j++) {
                res.data.data[i].user[j].key = j;
              }
            }
            this.qxlist = res.data.data;
          } else {
            this.qxlist = [];
          }
        });
    },
    savchecked() {
      console.log(this.treeData);
      this.qxloding_flag = true;
      this.axios
        .post(
          this.$store.state.baseurl + "/wxapi/samt_qxEdit.php",
          qs.stringify({
            dk: null,
            token: sessionStorage.getItem("smt_token"),
            gsbm: this.qxvalue.GSBM,
            name: this.qxvalue.NAME,
            type: this.tab_current,
            treedata: JSON.stringify(this.treeData)
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.qxloding_flag = false;
            this.qxgl_tk_flag = false;
            this.tab_current = "gn";

            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.qxloding_flag = false;

            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    gsbmChange(value) {
      console.log(`selected ${value}`);
    }
  },

  components: {
    headercom,
    rightnav
  },
  created() {
    this.getqxgl();
    // this.qxlistclick()
  }
};
</script>

<style lang='less' >
.qxgl_page {
  .qxgl_box {
    position: relative;
    top: 140px;
    width: 98%;
    left: 1%;
    // height: 800px;
    min-height: 800px;
    background: #fff;
    text-align: left;
    .qxlb {
      padding: 20px;
      ul {
        li {
          margin: 10px 0;
          .add_ico {
            font-size: 20px;
            color: #1890ff;
            vertical-align: middle;
            margin-right: 10px;
          }
          .gsmc_tit {
            display: inline-block;
            // width: 16%;
            cursor: pointer;
          }
          .qx_gl_ry {
            width: 95%;
            margin-left: 30px;
            position: relative;
            .spin_box {
              position: absolute;
              top: 0;
              left: 0;
              z-index: 999;
              width: 100%;
              height: 800px;
              background: rgba(255, 255, 255, 0.5);
              text-align: center;
              .ant-spin {
                position: absolute;
                top: 33%;
                left: 39%;
                transform: translate(-50%, -50%);
              }
            }
            ul {
              li {
                .qx_chil_box {
                  display: flex;
                  width: 30%;
                  justify-content: space-between;
                  .qxy_tit {
                  }
                  .cz_box {
                  }
                  .cz_box a {
                    margin: 0 10px;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  .qx_hedlist {
    position: fixed;
    top: 65px;
    width: 80% !important;
    left: 11%;
    height: 60px;
    background-color: #fff;
    text-align: left;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    .head_search .sele i {
      position: absolute;
      top: 22px;
      right: 31px;
    }
  }
  .qxgl_tk {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 1000px;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    .qx_edit {
      position: absolute;
      top: 3%;
      left: 50%;
      transform: translate(-50%, 0%);
      width: 40%;
      max-height: 800px;
      background: #fff;
      padding: 20px;
      .edit_spin_box {
        position: absolute;
        top: 84px;
        left: 0;
        z-index: 999;
        width: 100%;
        height: 700px;
        background: rgba(255, 255, 255, 0.5);
        text-align: center;
        .ant-spin {
          position: absolute;
          top: 33%;
          left: 39%;
          transform: translate(-50%, -50%);
        }
      }
      .tab_box {
        overflow: hidden;
        overflow-y: scroll;
        height: 550px;
        position: relative;
        left: 80px;
        .check_box {
          text-align: left;
          padding: 0 26px;
          .can_check {
            margin-left: 20px;
            color: #40a9ff;
          }
        }
      }
      .qx_btn_box {
        button {
          margin: 0 20px;
        }
      }
    }
    @media (max-width: 1500px) {
      .qx_edit {
        width: 45%;

        height: 500px;
        overflow-y: scroll;
        .tab_box {
          // height: 480px;
        }
      }
    }
  }
  .add_newkh {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 1000px;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;

    .kh_from {
      position: absolute;
      top: 10%;
      left: 50%;
      transform: translateX(-50%);
      width: 40%;
      height: 450px;
      background: #fff;
      text-align: left;
      padding: 30px;
      .tit {
        text-align: center;
        font-size: 20px;
      }
      ul {
        li {
          margin: 20px 0;
          text-align: center;
          .inp_tit {
            display: inline-block;
            width: 100px;
            text-align: right;
            margin-right: 20px;
          }
        }
        .btn_li {
          text-align: center;
          button {
            margin: 0 20px;
          }
        }
      }
    }
  }
  .red {
    color: red;
  }
  .ant-tabs-bar{
    border: 0;
    text-align: left;
    padding: 20px 40px 10px;
  }
}

// .spin-content {
//   border: 1px solid #91d5ff;
//   background-color: #e6f7ff;
//   padding: 30px;
// }
</style>
